﻿using Avalonia;
using iOSClub.Toolkit.WindowApp.ViewModels;

namespace iOSClub.Toolkit.WindowApp.Pages;

public static class ViewServes
{
    public static T? GetView<T>(StyledElement? control) where T : StyledElement
    {
        while (true)
        {
            if (control is null) return default;
            if (control is T t) return t;
            control = control.Parent;
        }
    }

    public static T? GetViewData<T>(StyledElement? control) where T : ViewModelBase
    {
        while (true)
        {
            if (control is null) return default;
            if (control.DataContext is T t) return t;
            control = control.Parent;
        }
    }
}